var KnowledgeManagementPage = {
	// 构造操作列
	'buildOpt':function(){
		var $opt = $("<div class='t-opt-btn-group'/>");
		var buildDetailItem = function(text, className, icon){
			var $span = $("<span>");
			$span.attr("title",text);
			var $a = $("<a>");
			$a.attr({
				'class':className,
				'href':'javascript:void(0);'
			});
			var $icon = $("<i class='icon'/>");
			$icon.addClass(icon);
			$a.append($icon);
			
			$span.append($a);
			$opt.append($span);
		};
		buildDetailItem('修改','editABtn','icon-edit');
		buildDetailItem('删除','tableDelbtn','icon-trash');
		buildDetailItem('预览','previewbtn','icon-eye-open');
		return $opt;
	},
	// questionLstTable渲染每一项
	'onRenderItem':function(colName,text,indexStr,mItem) {
		switch(colName){
		case '':
			return KnowledgeManagementPage.buildOpt();
		case 'status':
			var txt = (text == '0' || text == 0)? "禁用" : "正常";
			var color = (text == '0' || text == 0)?"red" : "green";
			return '<span style="color:' + color + '">' + txt + '</span>';
		}
	},
	// questionLstTable表格初始化完成
	'onAfterReady':function() {
		$(".editABtn").click(function(e){
			e.stopPropagation();
			e.preventDefault();
			var num = $(this).parents('tr').index();
			var id = questionLstTable.rows[num].data[0];
			var url = ctx+"/sms/knowlegeManage/updateKnowledge/"+id;
			MsgBox.open("updateKnowledge", "编辑知识", url, '1000px');
		});
		$(".tableDelbtn").click(function(e){
			var num = $(this).parents('tr').index();
			var record = questionLstTable.rows[num];
			MsgBox.confirm("确认删除问题【"+record.data[2].text+"】？","删除确认",function(){
				var id = record.data[0];
				delQuestionsAjax.setData({
					'delIds':[id]
				});
				delQuestionsAjax.send();
			},null);
			e.stopPropagation();
			e.preventDefault();
		});
		$(".previewbtn").click(function(e){
			var num = $(this).parents('tr').index();
			var id = questionLstTable.rows[num].data[0];
			console.log(id);
			var url = ctx+"/sms/knowledge/repos/show/"+id;
			MsgBox.open("preview","预览",url, '1000px');
			e.stopPropagation();
			e.preventDefault();
		});
	},
	'resetQuery':function(){
		$("#queryKnowledgeFrm")[0].reset();
	},
	// 打开编辑知识对话框
	'openEditKnowledgeDialog':function(){
		MsgBox.open("addKnowledge","新增知识",ctx + "/sms/knowlegeManage/addKnowledge","1000px");
	},
	// 批量删除
	'batchDel':function() {
		var selectRecords = questionLstTable.getSelectedRecords();
		if(selectRecords == null || selectRecords.length == 0){
			MsgBox.warn("请至少选择一条记录","消息提示",null);
		}else{
			MsgBox.confirm("确认删除所选 "+selectRecords.length+" 条问题信息？","删除确认",function(){
				var ids = $.toPropertyValueArray($.toPropertyValueArray(selectRecords, 'data'),'question_id');
				Logger.warn("选中的数据ID => " + JSON.stringify(ids));
				delQuestionsAjax.setData({
					'delIds':ids
				});
				delQuestionsAjax.send();
			},null);
		}
	},
	// 批量删除成功
	'onBatchDelKnowledgeSucc':function(data,status,xhr) {
		MsgBox.info(data.message, null, function(){
			questionLstTable.refresh();
		});
	},
	// 刷新知识管理表格
	'refreshKnowledgeTable':function() {
		questionLstTable.refresh();
	},
	// 条件查询
	'query':function() {
		queryQuestionAjax.send();
	}
	
};

